package com.tich.program.controller;

import com.tich.constant.ResponseMessageConstant;
import com.tich.context.UserContext;
import com.tich.program.domain.dto.*;
import com.tich.program.domain.vo.ProgramCategoryVO;
import com.tich.program.domain.vo.ProgramSelectVO;
import com.tich.program.domain.vo.ProgramSimpleSelectVO;
import com.tich.program.domain.vo.ProgramSimpleVO;
import com.tich.program.service.IProgramCategoryService;
import com.tich.program.service.IProgramService;
import com.tich.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/program")
public class ProgramController {

    @Autowired
    private IProgramService iProgramService;

    /**
     * 查询所有节目的简略信息
     * @param programSimpleSelectDTO
     * @return
     * */
    @PostMapping("/simple")
    public Result<ProgramSimpleVO> simpleSelectProgram(@RequestBody ProgramSimpleSelectDTO programSimpleSelectDTO){
        //TODO 目前根据更新时间进行推荐，以后考虑修改
        log.info("查询所有节目的简略信息，相关数据：{}", programSimpleSelectDTO);
        return Result.success(ResponseMessageConstant.QUERY_SUCCESS, iProgramService.querySimpleProgram(programSimpleSelectDTO));
    }

    /**
     * 查询节目详细信息
     * @param id
     * @return
     * */
    @GetMapping
    public Result<ProgramSelectVO> selectProgram(Long id){
        log.info("查询节目详细信息，id：{}", id);
        return Result.success(ResponseMessageConstant.QUERY_SUCCESS, iProgramService.selectProgram(id));
    }

    /**
     * 新增节目业务
     * @param programSaveDTO
     * @return
     * */
    @PostMapping
    public Result saveProgram(@RequestBody ProgramSaveDTO programSaveDTO){
        //TODO 添加用户身份判断是不是管理员
        log.info("新增节目:{}", programSaveDTO);
        iProgramService.saveProgram(programSaveDTO);
        return Result.success(ResponseMessageConstant.SAVE_SUCCESS);
    }

    /**
     * 修改节目信息
     * @param programUpdateDTO
     * @return
     * */
    @PutMapping
    public Result updateProgram(@RequestBody ProgramUpdateDTO programUpdateDTO){
        log.info("修改节目信息:{}", programUpdateDTO);
        iProgramService.updateProgram(programUpdateDTO);
        return Result.success(ResponseMessageConstant.UPDATE_SUCCESS);
    }

    /**
     * 删除节目信息
     * @param id
     * @return
     * */
    @DeleteMapping
    public Result deleteProgram(Long id){
        log.info("删除节目：{}", id);
        iProgramService.deleteProgram(id);
        return Result.success(ResponseMessageConstant.DELETE_SUCCESS);
    }

}
